<?php
class Newconnection extends CI_Model
{
    function recently_arrived($id,$status)
    {
        
        $query = $this->db->query("SELECT
                                newconnection.appid,
                                newconnection.applydate,
                                newconnection.updatedate,
                                newconnection.result,
                                newconnection.accomplishdate
                                FROM
                                newhandle
                                Inner Join newconnection ON newhandle.appid = newconnection.appid
                                WHERE
                                empid = '$id' and status='$status'");
        return $query;

    }
    function update_status($id,$status)
    {
        
        $this->db->set('status', $status);
        $this->db->set('updatedate', 'NOW()', FALSE);
        $this->db->where("appid",$id);
        $this->db->update('newconnection');

    }
    function update_message($appid,$msg)
    {
        
        $this->db->set('message', $msg);
        $this->db->set('updatedate', 'NOW()', FALSE);
        $this->db->where("appid",$appid);
        $this->db->update('newconnection');
    }
    function forward_report($appid,$result,$cause)
    {

        $this->db->set('result', $result);
        if($result=='Negative')
            $this->db->set('cause', $cause);
        $this->db->set('updatedate', 'NOW()', FALSE);
        $this->db->where("appid",$appid);
        $this->db->update('newconnection');
    }
    function issue_final($appid,$result)
    {
        
    }
    function get_status($input)
    {
        $this->db->where($input);
        $query = $this->db->get('applicant');
        if($query->num_rows() > 0)
         {
            $this->db->where('appid',$input['Id']);
            $query = $this->db->get('newconnection');
            return $query->row_array();
         }
         else
         {
             $data['appid']=-1;
             return $data;
         }
        
    }
    function get_report($appid)
    {

   
    $query = $this->db->query('SELECT
                                newconnection.appid as "Application Id",
                                newconnection.applydate as "Date of Apply",
                                applicant.FirstName as "First Name",
                                applicant.LastName as "Last Name",
                                applicant.PresAdd as "Present Address",
                                applicant.PermAdd as "Permanent Address",
                                applicant.Email as "Email",
                                applicant.Birthday as "Birthday",
                                exchange.name as "Exchange Name"
                                FROM
                                newconnection
                                Inner Join applicant ON newconnection.appid = applicant.Id
                                Inner Join newhandle ON newconnection.appid = newhandle.appid
                                Inner Join exchange ON newhandle.code = exchange.code
                                WHERE newconnection.appid = '."'$appid'");
    return $query->row_array();
    }
}
?>
